# ########## Project setup ##########
PROJECT(ProSonic)
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.5)

if(COMMAND cmake_policy)
      cmake_policy(SET CMP0003 OLD)
    endif(COMMAND cmake_policy)

if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
      "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel"
      FORCE)
endif()

if(NOT PROSONIC_INSTALL_PREFIX)
  if(WIN32)
     set(PROSONIC_INSTALL_PREFIX "C:/ProSonic" CACHE PATH
     "PROSONIC_INSTALL_PREFIX: Install path prefix, prepended onto install directories."
      FORCE)
  else(WIN32)
     set(PROSONIC_INSTALL_PREFIX "/usr/local/prosonic" CACHE PATH
     "PROSONIC_INSTALL_PREFIX: Install path prefix, prepended onto install directories."
      FORCE)
  endif(WIN32)
endif(NOT PROSONIC_INSTALL_PREFIX)

set(CMAKE_INSTALL_PREFIX "${PROSONIC_INSTALL_PREFIX}" CACHE INTERNAL "Prefix prepended to install directories" FORCE)

option(PROSONIC_BUILD_DEV_TOOLS "Build game development tools along with engine" False)
option(PROSONIC_INSTALL_EXAMPLE_DATA "Install example game data to run with engine" True)


# ######### General setup ##########
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")

IF(WIN32)
IF(MINGW)
  SET(DIRECTX_LIBRARIES "-ldinput -lddraw -ldxguid -lwinmm -ldsound" CACHE STRING "DirectX libraries needed to build project")
  SET(CMAKE_CXX_FLAGS "-DALLEGRO_STATICLINK -fexpensive-optimizations -march=i586 -mmmx -msse")
  SET(CMAKE_C_FLAGS "-DALLEGRO_STATICLINK -funroll-loops -funswitch-loops -w -fexpensive-optimizations -march=i586 -mmmx -msse")
ENDIF(MINGW)
IF(MSVC)
  SET(DIRECTX_LIBRARIES "dinput.lib ddraw.lib dxguid.lib winmm.lib dsound.lib" CACHE STRING "DirectX libraries needed to build project")
  SET(CMAKE_CXX_FLAGS "/DALLEGRO_STATICLINK /arch SSE")
  SET(CMAKE_C_FLAGS "/DALLEGRO_STATICLINK /w /arch SSE")
ENDIF(MSVC)
ELSE(WIN32)
  SET(ALLEGRO_CONFIG "allegro-config" CACHE STRING "Path to allegro-config script")
  SET(CMAKE_CXX_FLAGS "-fexpensive-optimizations -march=i586 -mmmx -msse")
  SET(CMAKE_C_FLAGS "-w -funroll-loops -funswitch-loops -fexpensive-optimizations -march=i586 -mmmx -msse")
ENDIF(WIN32)


FIND_PACKAGE(Allegro REQUIRED)
INCLUDE_DIRECTORIES(${ALLEGRO_INCLUDE_DIRS})
IF(WIN32)
IF(MINGW)
  LINK_LIBRARIES("-mwindows")
ENDIF(MINGW)
IF(MSVC)
  LINK_LIBRARIES("/SUBSYSTEM:WINDOWS")
ENDIF(MSVC)
  LINK_LIBRARIES(${ALLEGRO_LIBRARIES})
  LINK_LIBRARIES(${DIRECTX_LIBRARIES})
ELSE(WIN32)
  EXEC_PROGRAM(${ALLEGRO_CONFIG} 
    ARGS --libs
    OUTPUT_VARIABLE ALLEGRO_CONFIG_LIBS
    RETURN_VALUE ret
    )
  LINK_LIBRARIES(${ALLEGRO_CONFIG_LIBS})
ENDIF(WIN32)    

find_package(HAWKNL REQUIRED)
include_directories(${HAWKNL_INCLUDE_DIR})
LINK_LIBRARIES(${HAWKNL_LIBRARY})

find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
LINK_LIBRARIES(${ZLIB_LIBRARIES})

add_subdirectory(Source/Engine)

if(PROSONIC_BUILD_DEV_TOOLS)
  add_subdirectory(Source/Tools/scriptcompiler)
  add_subdirectory(Source/Tools/spritecompiler)
  add_subdirectory(Source/Tools/pzfcompiler)
  add_subdirectory(Source/Tools/gmv2psd)
  add_subdirectory(Source/Tools/limp)
endif(PROSONIC_BUILD_DEV_TOOLS)

if(PROSONIC_INSTALL_EXAMPLE_DATA)
  install(FILES ${CMAKE_SOURCE_DIR}/Data/Engine/*.* DESTINATION ${CMAKE_INSTALL_PREFIX})
endif(PROSONIC_INSTALL_EXAMPLE_DATA)
